package com.jbm.jbmsupplier.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.views.PledgeViews;
import com.jbm.onehome.iface.IorderEntity;

import java.util.List;

/**
 * Created by 家帮忙 on 2017/4/11.
 */

public class PledgeAdapterList extends BaseAdapter {
    private Context context;
    private List<IorderEntity> arr;
private PledgeViews orderDataServerChang;

    public PledgeAdapterList(Context context, List<IorderEntity> arr,PledgeViews orderDataServerChang) {
        this.orderDataServerChang=orderDataServerChang;
        this.context = context;
        this.arr = arr;
    }

    @Override
    public int getCount() {
        return arr.size();
    }

    @Override
    public Object getItem(int position) {
        return arr.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Viewholder viewholder;
        if (convertView==null){
             convertView=View.inflate(context, R.layout.month_layout,null);
            viewholder=new Viewholder(convertView);
            convertView.setTag(viewholder);
        }else{
            viewholder= (Viewholder)convertView.getTag();
        }
        IorderEntity polis = arr.get(position);
        initviewdate(viewholder,polis);
        return convertView;
    }
public void setDataAll(List<IorderEntity> arrs){
    arr=arrs;
    notifyDataSetChanged();

}
    private void initviewdate(Viewholder viewho,IorderEntity lis) {
if (lis.getOrderCode()!=null){
    viewho.dingdanbianhoa.setText("订单编号:"+  lis.getOrderCode());
}

        if (lis.getItemAmount()!=null) {
            viewho.cailiaofei.setText("材料费:" + lis.getItemAmount().intValue());
        }
        if (lis.getJobAmount()!=null) {
            viewho.weixiufei.setText("维修费:" + lis.getJobAmount().intValue());
        }
        double fuw = 0;
        if (orderDataServerChang.getServerChang()==0){
            viewho.fuwufei.setText("服务费:"+  0);
        }else {
            if (lis.getAmount()!=null){
                fuw=   Math.rint((lis.getAmount().doubleValue()*orderDataServerChang.getServerChang())/100);
                viewho.fuwufei.setText("服务费:"+  (int)fuw);
            }

        }
        if (lis.getAmount()!=null) {
            double zje = lis.getAmount().intValue() -fuw;
            viewho.zongji.setText("总额:" + (int)zje);
        }

        if (lis.getCreateDate()!=null) {
            viewho.baoxiushijian.setText("报修时间:" + lis.getCreateDate());
        }


        if (lis.getStatus()!=null){
            if (lis.getStatus().equals("completed")) {
                viewho.zhuangtai.setText("未付款");
                        }
          else
            if (lis.getStatus().equals("payed")) {
                viewho.zhuangtai.setText("已付款");
                }


        }





//        if (lis.getCreateDate()!=null){
//        viewho.time.setText(DataFormate.formate(DataFormate.StringF,lis.getCreateDate()));}
//        if (lis.getAmount().intValue()>0) {
//            viewho.money.setText("+"+lis.getAmount().intValue());
//            viewho.money.setTextColor(Color.parseColor("#3791DC"));
//        }else{
//        viewho.money.setText(lis.getAmount().intValue()+"");
        if(Float.parseFloat(lis.getAmount()+"")<0.0){
//            viewho.money.setTextColor(Color.parseColor("#1f1f1f"));
        }else{
//            viewho.money.setTextColor(Color.parseColor("#2495ee"));
        }




//        }
    }



        class Viewholder{
            public  TextView dingdanbianhoa,zongji,cailiaofei,weixiufei,fuwufei,baoxiushijian,zhuangtai;
        public Viewholder(View view) {
            dingdanbianhoa=(TextView)view.findViewById(R.id.dingdanbianhoa);
            zongji=(TextView)view.findViewById(R.id.zongji);
            cailiaofei=(TextView)view.findViewById(R.id.cailiaofei);
            weixiufei=(TextView)view.findViewById(R.id.weixiufei);
            fuwufei=(TextView)view.findViewById(R.id.fuwufei);
            baoxiushijian=(TextView)view.findViewById(R.id.baoxiushijian);
            zhuangtai=(TextView)view.findViewById(R.id.zhuangtai);


        }
    }
}
